package edu.scau.hot.web.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.scau.hot.entity.HotDiscount;
import edu.scau.hot.service.IHotDiscountService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (HotDiscount)表控制层
 *
 * @author PaperEasyCode
 * @since 2022-03-02 15:26:27
 */
@RestController
@RequestMapping("hotDiscount")
public class HotDiscountController{
    /**
     * 服务对象
     */
    @Resource
    private IHotDiscountService hotDiscountService;

    /**
     * 分页查询
     *
     * @param pageNum     起始页
     * @param pageSize    每页数据大小
     * @param hotDiscount 筛选条件
     * @return 查询结果
     */
    @GetMapping("/page")
    public PageInfo page(@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") Integer pageSize,HotDiscount hotDiscount) {
        PageHelper.startPage(pageNum,pageSize);
        List<HotDiscount> list = hotDiscountService.queryAll(hotDiscount);
        return new PageInfo(list);
    }

    /**
     * 查询所有数据
     *
     * @param hotDiscount 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public ResponseEntity<List<HotDiscount>> queryAll(HotDiscount hotDiscount) {
        return ResponseEntity.ok(this.hotDiscountService.queryAll(hotDiscount));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<HotDiscount> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.hotDiscountService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param hotDiscount 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<HotDiscount> add(@RequestBody HotDiscount hotDiscount) {
        return ResponseEntity.ok(this.hotDiscountService.insert(hotDiscount));
    }

    /**
     * 编辑数据
     *
     * @param hotDiscount 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<HotDiscount> edit(@RequestBody HotDiscount hotDiscount) {
        return ResponseEntity.ok(this.hotDiscountService.update(hotDiscount));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.hotDiscountService.deleteById(id));
    }

}

